#include <iostream>
#define MAXN 100
using namespace std;
bool used[MAXN];
int seq[MAXN];

void permulate(int index, int n) {
    if (index >= n) {
        for (int i = 0; i < n; i++)
            cout << seq[i] << ' ';
        cout << endl;
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            used[i] = true;
            seq[index] = i;
            permulate(index + 1, n);
            used[i] = false;
        }
    }
}

int main() {
    int n;
    cin >> n;
    permulate(0, n);
    return 0;
}